﻿<link href="/SiteUI/Purchase/share.css" rel="stylesheet" />
<link href="/SiteUI/Purchase/wgNewOrder.css" rel="stylesheet" />

<!--内部ERP订货单，也是还没有得到卖方确认的订单-->
<div class="col-lg-12" id="pch-wgNewOrder">
    <div class="row">
        <div class="col-lg-12 head">
            <h4><i class="icon-dashboard"></i>采购-待确认订单<span id="pch-tipCount">(-)</span></h4>
            <a class="Lite" href="/Purchase/MyOrders?status=pending">查看全部订单>></a>
        </div>
        <div class="col-lg-12" id="pch-lstNewOrder">
            
        </div>
        <div class="col-lg-12" id="ListPaging"></div>
    </div>
</div>
<script src="/LiberUI/Scripts/laytpl.js"></script>
<!--待确认新订单列表项模板-->
<script class="tplPchNewOrder" type="text/html" style="display:none">
    <div class="row noItem" objid="{{d.idstr}}">
        <div class="col-lg-1 no-row-head">
            <img src='{{d.supplier_logo}}' />  <!--供应商Logo-->
        </div>
        <div class="col-lg-11 no-row-body">
            <div class="row no-headline">
                <div class="col-lg-4 no-tradeno">
                    <span >交易编号：</span><span>{{d.idstr}}</span>
                </div>
                <div class="col-lg-5 no-supplier">
                    <span><i class="soicon icon-004office"></i>&nbsp;{{d.supplier}}</span>
                </div>
                <div class="col-lg-3 no-lnks">
                    <a class="LinkTo" target="_blank" href="/Trade/OrderDetail?oid={{d.idstr}}">查看详情>></a>
                </div>
            </div>
            <div class="row no-describe">
                <div class="col-lg-4">
                    <span>内部订单：</span><span>{{d.src_orderserial}}[{{d.src_orderversion||'-'}}]</span>
                    <br />
                    <span>订货日期：</span><span>{{d.orderdate}}</span>
                    <br />
                    <span>收&nbsp;&nbsp;货&nbsp;&nbsp;人：</span>
                    <span>{{d.consignee_displayname}}</span>
                    <br />
                </div>
                <div class="col-lg-4 withLeftIndent">
                    <span>订单金额：</span><span><strong>{{d.amountStr}}</strong></span>
                    <br />
                    {{#if(d.urgent==true){ }}
                    <span>交货日期：</span><span class="urgent" title="交货日期已临近，请注意跟进">{{d.deliverydate}}<i class="icon-erroroutline"></i></span>
                    {{#}else{ }}
                    <span>交货日期：</span><span >{{d.deliverydate}}</span>
                    {{#} }}
                    <br />
                    {{#if(d.saler_idstr){ }}
                        <span>销售经办：</span><a class="Lite People certificated" objid="{{d.saler_idstr}}"><img src='{{d.saler_headimg}}'/>{{d.saler}}</a>
                    {{#}else{ }}
                        <span>销售经办：</span><span class="People no-certificated"><i class="soicon icon-accountcircle"></i>{{d.saler}}</span>
                    {{#} }}                 
                    <br />
                </div>
            </div>
        </div>
    </div>
</script>

<script>
    wgPchNewOrder = {
        onlymine:false,
        newOrders: [],
        tplNewOrder: null,
        lstNewOrders: null,
        ListPaging: null,
        cnd:{
            onlymine: false,
            status:'Pending',
            page: 1,
            num: 5
        },
        query: function (recount) {
            wgPchNewOrder.lstNewOrders.vl(null)
                                      .update();
            if (User.DataRange.onlymine == false && User.Authority.findObj("auth", "Purchase|Order|Admin") == null) {
                wgPchNewOrder.lstNewOrders.Empty("抱歉，您没有查看部门订单的权限").update();
                wgPchNewOrder.ListPaging.hide();
            }
            else {
                wgPchNewOrder.cnd.onlymine = User.DataRange.onlymine;
                if (recount) {
                    $.getJSON("/Purchase/CountOrders", wgPchNewOrder.cnd, wgPchNewOrder.onCountEnd);
                }
                wgPchNewOrder.lstNewOrders.Loading("正在努力加载...");
                $.getJSON("/Purchase/QueryOrders", wgPchNewOrder.cnd, wgPchNewOrder.onGetNewOrdersEnd);
            }
            
        },
        GoPage: function (pg) {
            wgPchNewOrder.cnd.page = pg;
            wgPchNewOrder.query();
        },
        makeOrderView: function ($item, od) {           
            od.supplier_logo =od.supplier_logo||"/UserFile/DefaultCompanyLogo.gif";
            od.supplier = od.supplier || od.src_supplier;
            od.saler = od.saler || od.src_saler;
            od.consignee_displayname = od.src_consignee || od.consignee_realname;
            od.orderdate = new Date(od.src_orderdate||od.createtime).toString();
            od.deliverydate = new Date(od.src_deliverydate || od.deliverydate).toString();
            od.urgent = daysBetween(new Date(od.src_deliverydate || od.deliverydate).toString(), new Date().toString())<5;
            od.amountStr = od.amount.roundTo(2).toThousands();
            od.taxrate = od.taxrate + "%";

            var v = wgPchNewOrder.tplNewOrder.render(od);

            if (od.status == 'Pending' && od.src_orderversion && od.src_orderversion.split('-')[1] != '01') {
                $(v).addClass("withHistory");
            }
            $item.append($(v).addClass("fladeInUp"));
        },
        onGetNewOrdersEnd: function (rtn) {
            if (rtn.IsPositive) {
                wgPchNewOrder.lstNewOrders.vl(rtn.Data["Orders"])
                                          .Empty("没有符合条件的记录")
                                          .update();
            }
        },
        onCountEnd: function (rtn) {
            console.log(rtn);
            if (rtn.IsPositive) {
                $("#pch-tipCount").vl("(" + rtn.Data["Total"] + ")");
                //分页控件
                console.log(rtn.Data["Total"]);
                wgPchNewOrder.ListPaging.option("Total", rtn.Data["Total"])
                                        .option("CurrPage", 1)
                                        .update();
            }
        }
    }

    $(function () {     
        wgPchNewOrder.tplNewOrder = laytpl($(".tplPchNewOrder")[0].innerHTML);  //定义模板实例
        wgPchNewOrder.lstNewOrders = new LiberUI.Lister("#pch-lstNewOrder")
                                                .option("Slctble", false)
                                                .option("ContentRender", wgPchNewOrder.makeOrderView)
                                                .Loading("正在努力加载...");

        wgPchNewOrder.ListPaging = new LiberUI.Paging("#ListPaging")
                                              .option("BtnClick", wgPchNewOrder.GoPage)
                                              .option("Row", 5);
                                         
        if (User) {
            wgPchNewOrder.query(true);
        }
        else {
            $("body").on("UserReady", function () { wgPchNewOrder.query(true); });
        }
        $("body").on("DataRangeChanged", function () { wgPchNewOrder.query(true); });
    })
</script>
